//package com.example.project.projectspringcloud.common.log;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.converter.HttpMessageNotReadableException;
//import org.springframework.web.HttpMediaTypeNotSupportedException;
//import org.springframework.web.HttpRequestMethodNotSupportedException;
//import org.springframework.web.bind.MethodArgumentNotValidException;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.ResponseStatus;
//
///**
// * Title: 全局异常处理切面
// * Description: 利用 @ControllerAdvice + @ExceptionHandler 组合处理Controller层RuntimeException异常
// *
// * @author rico
// * @created 2017年7月4日 下午4:29:07
// */
//@ControllerAdvice   // 控制器增强
//@ResponseBody
//public class ExceptionAspect {
//
//    /**
//     * Log4j日志处理(@author: rico)
//     */
//    private static final Logger logger = LoggerFactory.getLogger(ExceptionAspect.class);
//
//    /**
//     * 400 - Bad Request
//     */
//    @ResponseStatus(HttpStatus.BAD_REQUEST)
//    @ExceptionHandler(HttpMessageNotReadableException.class)
//    public Response handleHttpMessageNotReadableException(
//            HttpMessageNotReadableException e) {
//        logger.error("could_not_read_json...", e);
//        return new Response().failure("could_not_read_json");
//    }
//
//    /**
//     * 400 - Bad Request
//     */
//    @ResponseStatus(HttpStatus.BAD_REQUEST)
//    @ExceptionHandler({MethodArgumentNotValidException.class})
//    public Response handleValidationException(MethodArgumentNotValidException e) {
//        logger.error("parameter_validation_exception...", e);
//        return new Response().failure("parameter_validation_exception");
//    }
//
//    /**
//     * 405 - Method Not Allowed。HttpRequestMethodNotSupportedException
//     * 是ServletException的子类,需要Servlet API支持
//     */
//    @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
//    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
//    public Response handleHttpRequestMethodNotSupportedException(
//            HttpRequestMethodNotSupportedException e) {
//        logger.error("request_method_not_supported...", e);
//        return new Response().failure("request_method_not_supported");
//    }
//
//    /**
//     * 415 - Unsupported Media Type。HttpMediaTypeNotSupportedException
//     * 是ServletException的子类,需要Servlet API支持
//     */
//    @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
//    @ExceptionHandler({HttpMediaTypeNotSupportedException.class})
//    public Response handleHttpMediaTypeNotSupportedException(Exception e) {
//        logger.error("content_type_not_supported...", e);
//        return new Response().failure("content_type_not_supported");
//    }
//
//    /**
//     * 500 - Internal Server Error
//     */
//    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//    @ExceptionHandler(TokenException.class)
//    public Response handleTokenException(Exception e) {
//        logger.error("Token is invaild...", e);
//        return new Response().failure("Token is invaild");
//    }
//
//    /**
//     * 500 - Internal Server Error
//     */
//    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//    @ExceptionHandler(Exception.class)
//    public Response handleException(Exception e) {
//        logger.error("Internal Server Error...", e);
//        return new Response().failure("Internal Server Error");
//    }
//}